<?php
class Account{
	public $balance;
	function __construct($balance){
		$this->balance = $balance;
	}
}


class Person{
	private $name;
	private $age;
	public $id;
	public $account;

	function __construct($name,$age,Account $account){
		$this->name = $name;
		$this->age = $age;
		$this->account = $account;
	}


	function setId($id){
		$this->id = $id;
	}

	function __clone(){
		$this->id = 0;
		$this->account = clone $this->account;
	}

	function getName(){
		return $this->name;
	}

	function getAge(){
		return $this->age;
	}
	//当把对象传递print或echo时，会自动调用这个方法，并用方法的返回值来替代默认的输出内容。
	function __toString(){
		$desc = $this->getName();
		$desc .= " (age ".$this->getAge().") ";
		return $desc;
	}
}

$person = new Person("Adair",18,new Account(200));
print $person."</BR>";
$person->setId(343);
print $person->account->balance."</BR>";
print $person->id."</BR>";

$person2 = clone $person;
$person->account->balance += 10;
print $person->account->balance."</BR>";
print $person2->account->balance."</BR>";
print $person2->id."</BR>";